#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()

<style>
    input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }

    input[type="number"] {
        -moz-appearance: textfield;
    }
</style>

#end

#define content()
<form class="layui-form">
    <h2>项目基本资料</h2>
    <hr class="layui-bg-red">
    <div class="layui-row layui-col-space10 layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><em class="require-mark">*</em>名称</label>
            <div class="layui-input-block" style="width: 300px">
                <input value="#(project.name)" id="model.name" name="project.name" lay-verify="required"
                       autocomplete="off" placeholder="请输入项目名称" class="layui-input" type="text">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><em class="require-mark">*</em>评估类型</label>
            <div class="layui-input-inline" style="width: 300px">
                <select id="project.paTypeID" name="project.paTypeID">
                    <option value="#(paTypeId)" selected="selected">#(paTypeName)</option>
                    #for(List : PaTypeNameList)
                    <option value="#(List.id)">#(List.name)</option>
                    #end
                </select>
            </div>

        </div>
        <div class="layui-inline" style="width: 400px">
            <label class="layui-form-label" for="project.amount"><em class="require-mark">*</em>预计金额</label>
            <div class="layui-input-inline" style="width: 250px">
                <input type="number" autocomplete="off" id="project.amount" name="project.amount"
                       value="#number(project.amount, '#')" class="layui-input money"lay-verify="required">
            </div>
            <div id="digitsTip"></div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
    </div>

    <div class="layui-row layui-col-space10 layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><em class="require-mark">*</em>立项身份</label>
            <div class="layui-input-inline" style="width: 300px">
                <select id="project.roleName" name="project.roleName">
                    <option selected="selected">#(project.roleName)</option>
                    #for(List : roleNameList)
                    <option>#(List)</option>
                    #end
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><em class="require-mark">*</em>项目阶段</label>
            <div class="layui-input-inline" style="width: 300px">
                <select id="project.pStepID" name="project.pStepID">
                    <option value="#(pStepId)" selected="selected">#(pStepName)</option>
                    #for(List : projectStepNameList)
                    <option value="#(List.id)">#(List.name)</option>
                    #end
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><em class="require-mark">*</em>评估方式</label>
            <div class="layui-input-block">
                <input class="btn layui-btn layui-btn-primary" type="button" id="zp" value="自评"/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input class="btn layui-btn layui-btn-primary" type="button" id="wp" value="委评"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><em class="require-mark">*</em>地 址</label>
        <div class="layui-input-block" style="width: 1160px">
            <input value="#(project.site)" id="model.site" name="project.site" lay-verify="required"
                   autocomplete="off" placeholder="请输入" class="layui-input" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><em class="require-mark">*</em>项目简介</label>
        <div class="layui-input-block" style="width: 1160px;">
            <textarea name="project.brief" id="demo" class="layui-textarea">#(project.brief)</textarea>
        </div>
    </div>
    <br>
    <h2>领导小组基本资料</h2>
    <hr class="layui-bg-orange">

    <div class="layui-row layui-col-space10 layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><em class="require-mark">*</em>组长</label>
            <div class="layui-input-block">
                <input value="#(leaderGroup.leader)" id="model.leader" type="text" name="leaderGroup.leader"
                       lay-verify="required" autocomplete="off" placeholder="请输入组长姓名" class="layui-input"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><em class="require-mark">*</em>副组长</label>
            <div class="layui-input-block">
                <input value="#(leaderGroup.deputy)" id="model.deputy" type="text" name="leaderGroup.deputy"
                       lay-verify="required" autocomplete="off" placeholder="请输入副组长姓名" class="layui-input"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><em class="require-mark">*</em>组员：</label>
            <div class="layui-input-block" style="width: 620px;">
                <input value="#(leaderGroup.crew)" id="model.crew" type="text" name="leaderGroup.crew"
                       lay-verify="required" autocomplete="off" placeholder="请输入组员姓名,用逗号间隔" class="layui-input"/>
            </div>
        </div>
    </div>
    <br>
    <p><h2>相关资料文件上传</h2><em class="require-mark">*</em>需将信息填写完整以及文件上传完毕后才可发起审核哦！（文件上传错误可再次上传）</p>
    <hr class="layui-bg-blue">
    <table style="align-content: center;" id="dateTable" lay-filter="dateTable"></table>
    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-left:500px;">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="sub">
                保存
            </button>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button type="reset" id="res" class="layui-btn layui-btn-warm">返回</button>
        </div>
    </div>
</form>
#end

<script type="text/html" id="barOption">
    #shiroHasPermission('/app/project/fileUploading')
    #[[
    {{#  if(!d.isUpLoad){ }}
    ]]#
        #[[
        {{#  if(d.status===1){ }}
        ]]#
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="upload">上传(必上传)</a>
        #[[
        {{# } else { }}
        ]]#
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="upload">上传(非必上传)</a>
        #[[
        {{#  } }}
        ]]#

    #[[
    {{# } else if(d.isUpLoad){ }}
    ]]#
    <a class="layui-btn layui-btn-xs " lay-event="upload">√ 已上传</a>
    <a class="layui-btn layui-btn-xs " lay-event="view">查看</a>

    #[[
    {{#  } }}
    ]]#
    #end
</script>
<!--<script type="text/javascript" src="/static/js/layui/layui.js"></script>-->
<!--<script type="text/javascript" src="/static/js/comm_notbar.js"></script>-->
<!--<script type="text/javascript" src="/static/js/utils.js"></script>-->
<!--<script type="text/javascript" src="/static/js/ztree/jquery-1.4.4.min.js"></script>-->
<script type="text/javascript" src="#(RESOURCE_HOST)/static/js/showMoney.js"></script>
<!--js start-->
#define js()
<script>
    var assessmentMode = '#(project.assessmentMode)';
    var projectID = "#(projectID)";
    var paTypeID = "#(paTypeId)";

    layui.use(['form', 'layer', 'element', 'laydate', 'table', 'layedit'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layedit = layui.layedit;

        var index = layedit.build('demo'); //建立编辑器

        /**
         * 文件表格
         */
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , id: 'dateTable'
            , even: true //开启隔行背景
            , size: 'sm' //小尺寸的表格
            , height: '500'    //容器高度
            , contentType: 'application/json; charset=UTF-8'
            , cols: [[                  //标题栏
                {type: 'numbers', fixed: true, unresize: 'true'}
                , {field: 'name', title: '需上传的文件', minWidth: 600}
                , {fixed: 'right', title: '操作', minWidth: 200, align: 'center', toolbar: '#barOption'} //这里的toolbar值是模板元素的选择器
            ]]
            , url: '#(ctxPath)/app/project/fileTable?id=' + projectID + '&paTypeID=' + paTypeID
            , method: 'get'
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true
            , limits: [30, 60, 90, 150, 300]
            , limit: 30 //默认采用30
            , loading: true
            , done: function (res, curr, count) {
            }
        });

        /**
         * 判断是否填写完整
         */
        function notNull() {
            var valueArray = [];
            var n = true;
            $(".model").each(function (key) {
                valueArray[key] = $(this).val();
                if (valueArray[key] == null || valueArray[key] == '')
                    n = false;
                return false;
            });
            if (!n) {
                return n;
            }
            if (layedit.getText(index) == null || layedit.getText(index) == '') {
                n = false;
            }
            return n;
        }

        form.on('submit(sub)', function (data) {
            if (!notNull()) {
                layer.msg('当前信息未填写完整！');
                setTimeout(function () {
                }, 1000);
                return false;
            } else {
                if (assessmentMode == '') {
                    layer.msg('请选择评估方式！');
                    setTimeout(function () {
                    }, 1000);
                    return false;
                }

                util.sendAjax({
                    type: 'POST',
                    url: '#(ctxPath)/app/project/saveProjectMessage?id=' + projectID + '&assessmentMode=' + assessmentMode + "&brief=" + layedit.getContent(index),
                    data: $.param(data.field),
                    loadFlag: true,
                    success: function (data) {
                        window.location.href = '#(ctxPath)/app/project/toBuildProject'
                    },
                    error: function (data) {
                        console.log(data);
                    }
                });
            }
        });

        $("#zp").click(function () {
            assessmentMode = '自评';
            console.log(assessmentMode);
            $("#zp").css("color", '#0fae7f');
            $("#wp").css("color", '#d9cfdc');
        });

        $("#wp").click(function () {
            assessmentMode = '委评';
            console.log(assessmentMode);
            $("#wp").css("color", '#0fae7f');
            $("#zp").css("color", '#d9cfdc');
        });



        table.on('tool(dateTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'upload') {
                layer.open({
                    type: 2,
                    area: ['500px', '300px'],
                    fix: false, //不固定
                    maxmin: false,
                    shadeClose: false,
                    shade: 0.4,
                    title: '上传文件',
                    content: '#(ctxPath)/app/project/fileUploading?id=' + data.id + '&projectId=' + projectID,
                    end: function () {
                        table.reload('dateTable', {
                            url: '#(ctxPath)/app/project/fileTable?id=' + projectID + '&paTypeID=' + paTypeID
                        });
                    }
                });
            } else if (obj.event === 'view') {
                pop_show('查看文件', '#(ctxPath)/util/pdfView?fileID=' + data.fileID, '', '', function () {
                });
            }
        });

    });

    $("#res").click(function () {
        history.go(-1);
    });

    $('.money').on('input propertychange', function() {
        var data = $('.money').val();
        var str = digitsConversion(data);
        var bid = parseInt(Math.random()*100000);
        $("#digitsTip").html('<div class="docBubble" id="btip'+bid+'"><i class="triangle-t"></i><div class="tl"><div class="inner"><div class="cont"></div></div></div><div class="tr"></div><div class="bl"></div></div>');
        var $btip = $("#btip"+bid);
        var offset,h ,w ;
        var timer;
        clearInterval(timer);
        offset = $(this).offset();
        h = $(this).height();
        w = $(this).width();
        $(".cont").html(str);
        $(".triangle-t").css('left',26);
        $btip.css({ "left":offset.left-330  ,  "top":offset.top+h-60  }).show();
    });

    $('.money').live("mousemove",function(){
        clearInterval(window.timer);
        $("#digitsTip").show();
    });

    $('.money').live("mouseout",function(){
        $("#digitsTip").hide();
    });
</script>
<!--js end-->
#end